﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Map_Creator.MainForm.Controls
{
    public partial class ChibiToolStrip : ToolStrip
    {
        public static ChibiToolStrip HoveredToolStrip;

        public event EventHandler Undocked;

        public ChibiToolStrip()
        {
            InitializeComponent();
        }

        private void OnMouseEnter(object sender, EventArgs e)
        {
            HoveredToolStrip = this;
        }

        protected override void OnMouseDown(MouseEventArgs mea)
        {
            if (GripRectangle.Contains(mea.Location))
            {
                Point location = PointToScreen(Point.Empty);

                // For more control, this would be a custom form.
                // You could then event handlers that would react
                // when it is dragged to an edge, and redock it
                // automatically.
                floatForm = new Form();
                floatForm.StartPosition = FormStartPosition.Manual;
                floatForm.Owner = FindForm();
                Point pt = location;
                pt.Offset(5, 5);
                floatForm.Location = pt;
                floatForm.Text = Text;
                floatForm.FormBorderStyle =
                  FormBorderStyle.FixedToolWindow;
                floatForm.ClientSize = Size;

                // A control can be contained in only one form.
                // This moves
                // the ToolStrip out of the original form and 
                // into the floating form.
                floatForm.Controls.Add(this);
                floatForm.Show();

                // Raise the event to notify the form.
                if (Undocked != null) Undocked(this, EventArgs.Empty);
            }
            else
            {
                // Perform the normal mouse-click handling.
                base.OnMouseDown(mea);
            }
        }


        private Form floatForm;
        public Form FloatForm
        {
            get { return floatForm; }
        }
    }
}
